class CommandsHistory(object):
    '''
    Class that provides a list of reversible operations (Commands)
        @ivar __commands: List of Command objects.
        @ivar __present: Index of current Command item. 
    '''
    __commands = []
    __present = 0
        
    def clear(self):
        self.__commands = []
        self.__present = 0
    
    def addCommand(self, cmd):
        '''Adds a new command to the history.'''
        self.__commands = self.__commands[:self.__present]
        self.__commands.append(cmd)
        self.__present += 1
    
    def undo(self):
        '''Goes back in history by one command'''
        #If there's at least one command
        if self.__present > 0:
            self.__commands[self.__present - 1].reverse()
            self.__present -= 1
    
    def redo(self):
        '''Repeat a command that was "undone".'''
        #If there's at least one command to repeat
        if self.__present < len(self.__commands):
            self.__commands[self.__present].execute()
            self.__present += 1